package client;

import static client.Config.getHost;
import logic.Document;
import logic.Template;
import net.SocketList;
import net.SocketLogon;
import net.SocketReporter;
import net.SocketRetriever;
import net.retrievers.Retriever;
import net.rmi.List;
import net.rmi.Logon;
import net.rmi.Reporter;
import net.tcp.TcpRemoteMethodInvocator;
import server.GlobalConfig;

public class TcpFactory extends Factory {

	private SocketRetriever<Template> socketRetriever;
	private SocketRetriever<Document> socketRetriever2;
	private SocketLogon socketLogon;
	private SocketReporter socketReporter;
	private SocketList socketList;

	@Override
	public Retriever<Document> getDocumentRetriever() {
		if (socketRetriever2 == null)
			socketRetriever2 = new SocketRetriever<Document>(Document.class, new TcpRemoteMethodInvocator(getHost(),
					GlobalConfig.TCP_DOCUMENT_RETR_PORT));
		return socketRetriever2;
	}

	@Override
	public Logon getLogon() {
		if (socketLogon == null)
			socketLogon = new SocketLogon(new TcpRemoteMethodInvocator(getHost(), GlobalConfig.TCP_LOGON_PORT));
		return socketLogon;
	}

	@Override
	public Reporter getReporter() {
		if (socketReporter == null)
			socketReporter = new SocketReporter(new TcpRemoteMethodInvocator(getHost(), GlobalConfig.TCP_REPORTER_PORT));
		return socketReporter;
	}

	@Override
	public Retriever<Template> getTemplateRetriever() {
		if (socketRetriever == null)
			socketRetriever = new SocketRetriever<Template>(Template.class, new TcpRemoteMethodInvocator(getHost(),
					GlobalConfig.TCP_TEMPLATE_RETR_PORT));
		return socketRetriever;
	}

	@Override
	public List getList() {
		if (socketList == null)
			socketList = new SocketList(new TcpRemoteMethodInvocator(getHost(), GlobalConfig.TCP_LIST_PORT));
		return socketList;
	}
}
